{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <div class="form-group">
                    <input type="hidden" id="id" value="{$data.id}">
                    <label for="name">支付名称</label>
                    <input type="text" class="form-control" id="name" value="{$data.name}"
                        placeholder="请输入支付名称">
                </div>
                <div class="form-group">
                    <label for="name">请求地址</label>
                    <input type="text" class="form-control" id="pay_url" value="{$data.pay_url}"
                        placeholder="请输入请求地址">
                </div>
                <div class="form-group">
                    <label for="appid">{if $data['payment_id'] == 0}应用appid{else /}商户id{/if}</label>
                    <input type="text" class="form-control" id="appid" value="{$data.appid}"
                        placeholder="请输入appid">
                </div>
                <div class="form-group">
                    <label for="detail">公钥</label>
                    <textarea class="form-control" id="public_key" rows="3"
                        placeholder="公钥(源支付不需要填)">{$data["public_key"]}</textarea>
                </div>
                <div class="form-group">
                    <label for="detail">商户私钥</label>
                    <textarea class="form-control" id="private_key" rows="3"
                        placeholder="商户私钥">{$data["private_key"]}</textarea>
                </div>
                <div class="form-group">
                    <label for="class_name">支付类名称</label>
                    <input type="text" class="form-control" id="class_name" value="{$data.class_name}"
                        placeholder="请输入支付类名称">
                        <small style="color:red;">不懂的话，不要瞎改此名称</small>
                </div>
                <button type="buttons" onclick="updatepay()" class="btn btn-w-sm btn-primary mb-2">提交</button>
                <button type="button" class="btn btn-default mb-2" onclick="javascript:history.back(-1);return false;">返
                    回
                </button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    function updatepay() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var id = $.trim($("#id").val());
        var pay_url = $.trim($("#pay_url").val());
        var name = $.trim($("#name").val());
        var public_key = $.trim($("#public_key").val());
        var private_key = $.trim($("#private_key").val());
        var appid = $.trim($("#appid").val());
        var class_name = $.trim($("#class_name").val());
        $.ajax({
            type: "POST",
            url: "{:url('payment/edit')}",
            data: {
                id: id,
                pay_url: pay_url,
                name: name,
                public_key: public_key,
                private_key: private_key,
                appid: appid,
                class_name: class_name,
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }

</script>
{/block}